import type { FormItemPerm } from "./FormComponentMixin";
export function getFormItemLabel(item) {
  if (item.tableKey && item.tableComment) {
    return item.tableComment + "." + item.columnComment;
  } else {
    return item.columnComment;
  }
}

export function getFormItemKey(item) {
  if (item.tableKey && item.tableComment) {
    return "#flowform." + item.tableKey + "." + item.columnKey;
  } else {
    return "#flowform." + item.columnKey;
  }
}

export function isDisplay(perm: FormItemPerm[], compCode: string) {
  if (perm && perm.length > 0) {
    const compIndex = perm.findIndex(n => n.columnKey === compCode);
    if (compIndex > -1) {
      if (perm[compIndex].displayType === "S") {
        return true;
      } else {
        return false;
      }
    } else {
      return true;
    }
  } else {
    return true;
  }
}

export function isReadonly(perm: FormItemPerm[], compCode: string) {
  if (perm && perm.length > 0) {
    const compIndex = perm.findIndex(n => n.columnKey === compCode);
    if (compIndex > -1) {
      if (perm[compIndex].permType === "R") {
        return true;
      } else {
        return false;
      }
    } else {
      return false;
    }
  } else {
    return false;
  }
}
